package com.neuedu.his.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neuedu.his.po.Constantitem;
import com.neuedu.his.service.ConstantitemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/constantitem")
public class ConstantItemController {

    @Autowired
    ConstantitemService service;

    @RequestMapping("/list")
    public List<Constantitem> list() {
        return service.list();
    }

    @RequestMapping("/getbytypeid")
    public List<Constantitem> getbytypeid(@RequestBody Map<String, String> id) {
        LambdaQueryWrapper<Constantitem> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Constantitem::getConstanttypeid, Integer.parseInt(id.get("id")));
        return service.list(queryWrapper);
    }

    @RequestMapping("/getbytypeid2")
    public List<Constantitem> getbytypeid2(@RequestParam Integer id) {
        QueryWrapper<Constantitem> qw = new QueryWrapper<>();
        qw.eq("constanttypeid", id);
        return service.list(qw);
    }

    @RequestMapping("/add")
    public Boolean add(@RequestBody Constantitem item) {
        return service.save(item);
    }

    @RequestMapping("/update")
    public Boolean update(@RequestBody Constantitem item) {
        return service.updateById(item);
    }

    @RequestMapping("/delete")
    public Boolean delete(@RequestBody Constantitem item) {
        return service.removeById(item.getId());
    }
}
